require("../util.js");
require("../component/components.js");
require("../../jsMt/util.js");
var vm = new Vue({
    el:"#transaction",
    data:{
        name:"",
        loginUid:"",
        pageNumber:1,
        walletLog:{},
        walletLog1:[],
        walletLog2:[]
    },
    mounted:function(){
        this.searchObject = this.getQueryStringArgs();
        this.loginUid=this.searchObject&&this.searchObject.uid;
        this.type=this.searchObject&&this.searchObject.type;
        if(this.type==1){
            this.name="交易中";
        }else if(this.type==2){
            this.name="结算中";
        }
        this.sellerorderFlow();
    },
    methods:{
        //后退
        getBack:function(){
            // history.go(-1);
            location.href="/happyi/incomeAssets?uid="+this.loginUid;
        },
        bgimg:function(url){
            url = url?url:"";
            return {
                "background-image":'url("'+url+'"),url("")'
            }
        },
        /*获取查询字符对象*/
        getQueryStringArgs: function () {
            //取得查询字符串并去掉开头的问号
            var qs = (location.search.length > 0 ? location.search.substring(1) : ""),
                args = {},
                items = qs.length ? qs.split("&") : [],
                item = null,
                name = null,
                value = null,
                len = items.length;
            for (var i = 0; i < len; i++) {
                item = items[i].split("=");
                name = item[0];
                value = item[1];
                if (name.length) {
                    args[name] = value;
                }
            }
            return args;
        },
        //订单流水
        sellerorderFlow:function(){
            var that=this;
            var data={
                loginUid:that.loginUid,
                pageNumber:that.pageNumber
            },url;
            if(that.type==1){
                url="/happyi/sellerorderListByTransaction"
            }else if(that.type==2){
                url="/happyi/sellerorderListBySettlement"
            }
            this.ajax({url:url,data:data,dataType:"json",method:"post"},function(b){
                if(b.json.code==0&&b.json.data){
                    that.walletLog=b.json.data;
                    that.walletLog1=that.walletLog.list;
                    if(that.walletLog.pageNumber>1){
                        if(that.walletLog.list.length>0) {
                            that.walletLog2 = that.walletLog2.concat(b.json.data.list);
                        }
                    }else{
                        that.walletLog2= that.walletLog1;
                    }
                    vm.loadFlag=false;
                }else{
                    that.walletLog={};
                    that.walletLog1=[];
                    that.walletLog2=[];
                    vm.$refs.prompt.toast("获取明细列表失败！")
                }
            });
        },
        //tab切换
        getTab:function(num){
            this.walletLog={};
            this.walletLog1=[];
            this.walletLog2=[];
            this.value=num;
            this.pageNumber=1;
            this.sellerorderFlow();
        },
        getNext:function(logId){
            location.href="/happyi/detailedInfo?logId="+logId+"&loginUid="+this.loginUid;
        }
    }
});
//文档高度
function getDocumentTop() {
    var scrollTop = 0, bodyScrollTop = 0, documentScrollTop = 0;
    if (document.body) {
        bodyScrollTop = document.body.scrollTop;
    }
    if (document.documentElement) {
        documentScrollTop = document.documentElement.scrollTop;
    }
    scrollTop = (bodyScrollTop - documentScrollTop > 0) ? bodyScrollTop : documentScrollTop;    return scrollTop;
}
//可视窗口高度
function getWindowHeight() {
    var windowHeight = 0;
    if (document.compatMode == "CSS1Compat") {
        windowHeight = document.documentElement.clientHeight;
    } else {
        windowHeight = document.body.clientHeight;
    }
    return windowHeight;
}
//滚动条滚动高度
function getScrollHeight() {
    var scrollHeight = 0, bodyScrollHeight = 0, documentScrollHeight = 0;
    if (document.body) {
        bodyScrollHeight = document.body.scrollHeight;
    }
    if (document.documentElement) {
        documentScrollHeight = document.documentElement.scrollHeight;
    }
    scrollHeight = (bodyScrollHeight - documentScrollHeight > 0) ? bodyScrollHeight : documentScrollHeight;
    return scrollHeight;

}
window.onscroll=function(){
    var loadFlag = vm.walletLog.lastPage;
    //监听事件内容
    if(getScrollHeight()==getWindowHeight() + getDocumentTop()){
        //当滚动条到底时,这里是触发内容
        if(!loadFlag){
            vm.loadFlag=true;
            vm.pageNumber++;
            vm.myWalletLog();
        }else{
            // console.log("11111");
            vm.$refs.prompt.toast("没有更多了！")
        }
    }
};